﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Xms.Core.Context;
using Xms.CRM.Data;
using Xms.CRM.Domain;
using Xms.Data.Provider;

namespace Xms.CRM
{
    public class CampusHolidayService : ICampusHolidayService
    {
        private readonly ICampusHolidayRepository _campusHolidayRepository;

        public CampusHolidayService(ICampusHolidayRepository campusHolidayRepository
            )
        {
            _campusHolidayRepository = campusHolidayRepository;
        }

        public Guid Create(CampusHoliday entity)
        {
            return _campusHolidayRepository.CreateEntity(entity);
        }

        public bool CreateMany(List<CampusHoliday> entitys)
        {
            return _campusHolidayRepository.CreateMany(entitys);
        }

        public bool Update(CampusHoliday entity)
        {
            return _campusHolidayRepository.Update(entity);
        }

        public bool Update(Func<UpdateContext<CampusHoliday>, UpdateContext<CampusHoliday>> context)
        {
            var ctx = context(UpdateContextBuilder.Build<CampusHoliday>());
            return _campusHolidayRepository.Update(ctx);
        }

        public CampusHoliday FindById(Guid id)
        {
            return _campusHolidayRepository.FindById(id);
        }

        public bool DeleteById(Guid id)
        {
            return _campusHolidayRepository.DeleteById(id);
        }

        public bool DeleteById(List<Guid> ids)
        {
            var flag = true;
            foreach (var id in ids)
            {
                flag = this.DeleteById(id);
            }
            return flag;
            //return _repository.DeleteById(ids);
        }

        public PagedList<CampusHoliday> QueryPaged(Func<QueryDescriptor<CampusHoliday>, QueryDescriptor<CampusHoliday>> container)
        {
            QueryDescriptor<CampusHoliday> q = container(QueryDescriptorBuilder.Build<CampusHoliday>());

            return _campusHolidayRepository.QueryPaged(q);
        }

        public List<CampusHoliday> Query(Func<QueryDescriptor<CampusHoliday>, QueryDescriptor<CampusHoliday>> container)
        {
            QueryDescriptor<CampusHoliday> q = container(QueryDescriptorBuilder.Build<CampusHoliday>());

            return _campusHolidayRepository.Query(q)?.ToList();
        }
    }
}
